package com.ikkong.platform.controller;

import java.util.Map;
import com.ikkong.core.base.BaseController;
import com.ikkong.core.jfinal.ext.kit.JsonKit;
import com.ikkong.platform.model.Owner;
import com.ikkong.platform.service.OwnerService;
import com.ikkong.platform.service.impl.OwnerServiceImpl;
import com.ikkong.system.controller.base.UrlPermissController;
import com.ikkong.platform.model.AccountAudit;
import com.ikkong.platform.service.AccountAuditService;
import com.ikkong.platform.service.impl.AccountAuditServiceImpl;

/**
 * Generated by Blade.
 * 2018-04-20 21:35:17
 */
public class AccountAuditController extends UrlPermissController {
	private static String CODE = "accountAudit";
	private static String PERFIX = "account_audit";
	private static String OWNER_PERFIX = "owner";
//	private static String LIST_SOURCE = "AccountAudit.list";
	private static String LIST_SOURCE = "Owner.list";
	private static String BASE_PATH = "/platform/accountAudit/";

	
	AccountAuditService service = new AccountAuditServiceImpl();
    OwnerService ownerService = new OwnerServiceImpl();

	public void index() {
		setAttr("code", CODE);
		render(BASE_PATH + "accountAudit.html");
	}

	public void add() {
		setAttr("code", CODE);
		setAttr("basePath", BASE_PATH);
		render(BASE_PATH + "accountAudit_add.html");
	}

	public void edit() {
		String id = getPara(0);
		AccountAudit accountAudit = service.findById(id);
		setAttr("model", JsonKit.toJson(accountAudit));
		setAttr("id", id);
		setAttr("code", CODE);
		render(BASE_PATH + "accountAudit_edit.html");
	}

	public void view() {
		String id = getPara(0);
		AccountAudit accountAudit = service.findById(id);
		setAttr("model", JsonKit.toJson(accountAudit));
		setAttr("id", id);
		setAttr("code", CODE);
		render(BASE_PATH + "accountAudit_view.html");
	}

	public void list() {
		Object grid = paginate(LIST_SOURCE);
		renderJson(grid);
	}

	public void save() {
		AccountAudit accountAudit = mapping(OWNER_PERFIX, AccountAudit.class);
		boolean temp = service.save(accountAudit);
		if (temp) {
			renderJson(success(SAVE_SUCCESS_MSG));
		} else {
			renderJson(error(SAVE_FAIL_MSG));
		}
	}

	public void update() {
        Owner owner = mapping(OWNER_PERFIX, Owner.class);
		boolean temp = ownerService.update(owner);
		if (temp) {
			renderJson(success(UPDATE_SUCCESS_MSG));
		} else {
			renderJson(error(UPDATE_FAIL_MSG));
		}
	}

	public void remove() {
		String ids = getPara("ids");
		int cnt = service.deleteByIds(ids);
		if (cnt > 0) {
			renderJson(success(DEL_SUCCESS_MSG));
		} else {
			renderJson(error(DEL_FAIL_MSG));
		}
	}
}
